<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.Connection,java.sql.Statement,java.sql.ResultSet,cn.com.chec.console.dao.DBFactory,java.util.List,java.util.ArrayList"%>
<%
String tblName = (String)request.getAttribute("tblName");
String sql = (String)request.getAttribute("sql");
Connection conn = DBFactory.getInstance().getConnection();
String descshowTable = "desc " + tblName ;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(descshowTable);
List<String> columns = new ArrayList<String>();
while(rs.next()){
	columns.add(rs.getString("Field"));
}
rs.close();
stmt.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SQL结果</title>
<%@include file="../../common/tagInclude.jsp" %>
<%@include file="../../common/headerInclude.jsp" %>
<script type="text/javascript">
$(function() {
	$("#jvForm").validate();
});
</script>
</head>
<body>
<div class="body-box">
	<div class="rhead">
		<div class="rpos">当前位置: 首页 - 系统 - <a href="${basePath}admin/dbTable/listTable.do">数据库</a> - SQL[<%=sql%>]</div>
		<div class="clear"></div>
	</div>
		<%
		try{
		Statement stmtQuery = conn.createStatement();
		ResultSet rsQuery = stmtQuery.executeQuery(sql);
		int index = 0 ;
		while(rsQuery.next()){
			index ++ ;
		%>
	<table class="pn-ltable" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
		<thead class="pn-lthead"><tr><th colspan="2"></th></tr></thead>
		<tbody class="pn-ltbody">
		<%
			for(String coloumn : columns ){
		%>
		<tr>
  			<td width='15%'><%=coloumn%></td>
  			<td><%=rsQuery.getString(coloumn)%></td>
  		</tr>
  		<%
			}
		%>
		</tbody>
	</table>
		<%
		}
		rsQuery.close();
		stmtQuery.close();
		if(index == 0 ){
			request.setAttribute("message",tblName + " 此表没有数据!");
			getServletContext().getRequestDispatcher("/WEB-INF/pages/common/message.jsp").forward(request,response);
			return ;
		}
		}catch(Exception ex){
			request.setAttribute("message","执行SQL错误!<br/> [" + sql + "]");
			getServletContext().getRequestDispatcher("/WEB-INF/pages/common/message.jsp").forward(request,response);
		} finally{
			if(conn != null)
				conn.close();
		}
		%>
		
</div>
</body>
</html>